package com.dci.service.impl.project;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.dci.context.Config;
import com.dci.dao.pms.project.*;
import com.dci.model.project.*;
import com.dci.param.SearchMap;
import com.dci.result.JsonData;
import com.dci.result.PageResult;
import com.dci.result.ResultInfo;
import com.dci.result.ResultUtil;
import com.dci.service.project.PlanInfoService;
import com.dci.service.project.ProjectInfoService;
import com.dci.util.UUIDBuild;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * All rights Reserved, Designed By 姑苏区政府大数据中心
 *
 * @version V1.0
 * @Title: null.java
 * @Package com.dci.service.impl.project
 * @Description: 项目管理实现类
 * @author: 张星亮
 * @date: 2019/2/25
 * @Copyright: 2019 姑苏区政府大数据中心. All rights reserved.
 * 注意：本内容仅限于姑苏区政府大数据中心内部传阅，禁止外泄以及用于其他的商业目
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ProjectInfoServiceImpl implements ProjectInfoService {

    @Resource
    private ProjectInfoMapper projectInfoMapper;

    @Resource
    private PlanInfoService planInfoService;

    @Resource
    private OutboundInfoMapper outboundInfoMapper;

    @Resource
    private ProjectManagerMapper projectManagerMapper;

    @Resource
    private ProjectTaskMapper projectTaskMapper;

    @Resource
    private ProjectScheduleMapper projectScheduleMapper;


    /**
     * 新增(暂时作废)
     *
     * @param projectInfo
     * @return
     */
    @Override
    public JsonData saveProjectInfo(ProjectInfo projectInfo) {

        // 判断新增 or 修改编辑
        if (projectInfo.getId() != null && !"".equals(projectInfo.getId())) {
            // 修改
            projectInfoMapper.updateByPrimaryKeySelective(projectInfo);
            return JsonData.success(projectInfo, 906);
        } else {
            // 新增
            projectInfo.setId(UUIDBuild.getUUID());
            // 项目状态,默认值为 0
            projectInfo.setStatus(0);
            // 审核状态默认 0
            projectInfo.setAuditStatus(0);
            // 审批状态 默认 0
            projectInfo.setApprovalStatus(0);
            // 出库状态是 默认 0
            projectInfo.setOutboundStatus(0);
            // 获取当前系统时间和日期并格式化输出:
            Date date = new Date();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            // 格式转换.String
            String dateTime = df.format(date);
            projectInfo.setDeclareTime(dateTime);
            // 删除标记 初始0
            projectInfo.setDelFlag("0");
            projectInfoMapper.insert(projectInfo);

            ProjectInfo projectInfoKey = new ProjectInfo();
            projectInfoKey.setId(projectInfo.getId());
            projectInfo = projectInfoMapper.selectByPrimaryKey(projectInfoKey);

            return JsonData.success(projectInfo, 906);
        }
    }

    @Override
    public List<ProjectInfo> selectByOutId(String selectByOutId) {
        return projectInfoMapper.selectByOutId(selectByOutId);
    }


    @Override
    public JsonData uploadAndSave(String object, String path, String fileNames) {
        Gson gson = new Gson();
        ProjectInfo projectInfo = gson.fromJson(object, ProjectInfo.class);
        // 判断新增 or 修改编辑
        if (projectInfo.getId() != null && !"".equals(projectInfo.getId())) {
            // 项目状态,默认值为 0
            projectInfo.setStatus(0);
            // 审核状态默认 0
            projectInfo.setAuditStatus(0);
            // 审批状态 默认 0
            projectInfo.setApprovalStatus(0);
            // 出库状态是 默认 0
            projectInfo.setOutboundStatus(0);
            // 获取当前系统时间和日期并格式化输出:
            Date date = new Date();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            // 格式转换.String
            String dateTime = df.format(date);
            projectInfo.setDeclareTime(dateTime);

            //不更新附件
            if ("".equals(fileNames) || fileNames == null) {
                projectInfoMapper.updateByPrimaryKeySelective(projectInfo);
                return JsonData.success(projectInfo, 906);
            }
        } else {
            // 新增
            projectInfo.setId(UUIDBuild.getUUID());
            // 项目状态,默认值为 0
            projectInfo.setStatus(0);
            // 审核状态默认 0
            projectInfo.setAuditStatus(0);
            // 审批状态 默认 0
            projectInfo.setApprovalStatus(0);
            // 出库状态是 默认 0
            projectInfo.setOutboundStatus(0);
            // 获取当前系统时间和日期并格式化输出:
            Date date = new Date();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            // 格式转换.String
            String dateTime = df.format(date);
            projectInfo.setDeclareTime(dateTime);
            projectInfo.setFilePath(path);
            projectInfo.setProjectFile(fileNames);
            // 删除标记 初始0
            projectInfo.setDelFlag("0");
            projectInfoMapper.insert(projectInfo);

            ProjectInfo projectInfoKey = new ProjectInfo();
            projectInfoKey.setId(projectInfo.getId());
            projectInfo = projectInfoMapper.selectByPrimaryKey(projectInfoKey);

            return JsonData.success(projectInfo, 906);
        }
        return JsonData.success(projectInfo, 906);
    }

    @Override
    public JsonData approvalAndSave(ProjectInfo projectInfo) {
        projectInfoMapper.updateByPrimaryKeySelective(projectInfo);
        return JsonData.success(projectInfo, 906);
    }


    @Override
    public JsonData selectProjectByPrimaryKey(ProjectInfo record) {
        ProjectInfo projectInfo = projectInfoMapper.selectByPrimaryKey(record);
        return JsonData.success(projectInfo, 906);
    }

    /**
     * 多条件分页查询
     *
     * @param projectInfo
     * @return
     */
    @Override
    public PageResult selectProjectPages(ProjectInfo projectInfo) {
        // 分页插件
        PageHelper.startPage(projectInfo.getPageNum(), projectInfo.getPageSize());
        List<ProjectInfo> list = projectInfoMapper.selectProjectPages(projectInfo);
        PageInfo<ProjectInfo> pageInfo = new PageInfo<>(list);
        Long count = pageInfo.getTotal();
        return PageResult.success(list, null, null, count);
    }

    @Override
    public ResultInfo updateProjectByPrimaryKeySelective(ProjectInfo projectInfo) {
        projectInfoMapper.updateByPrimaryKeySelective(projectInfo);
        return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
    }

    /**
     * 逻辑删除项目信息,逻辑删除管理信息
     *
     * @param list
     * @return
     */
    @Override
    public PageResult deleteProject(List<ProjectInfo> list) {
        if (list != null && list.size() != 0) {
            for (ProjectInfo projectInfo : list) {
                // 1为删除状态
                projectInfo.setDelFlag("1");
                projectInfoMapper.updateByPrimaryKeySelective(projectInfo);

                // 删除关联的进度计划表信息
                PlanInfo planInfo = new PlanInfo();
                planInfo.setProjectId(projectInfo.getId());
                planInfoService.deleteByProjectId(planInfo);
            }
        }
        // 删除后重新查询返回数据列表
        PageHelper.startPage(1, 10);
        list = projectInfoMapper.selectProjectPages(new ProjectInfo());
        PageInfo<ProjectInfo> pageInfo = new PageInfo<>(list);
        Long count = pageInfo.getTotal();
        return PageResult.success(list, null, null, count);
    }

    /**
     * 入库管理项目审核方法
     *
     * @param projectInfo
     * @return
     */
    @Override
    public ProjectInfo audit(ProjectInfo projectInfo) {
        if (projectInfo != null && projectInfo.getId() != null) {
            // 1审核通过状态
            projectInfo.setAuditStatus(1);
            projectInfoMapper.updateByPrimaryKeySelective(projectInfo);
        }
        ProjectInfo projectInfoKey = new ProjectInfo();
        projectInfoKey.setId(projectInfo.getId());
        projectInfo = projectInfoMapper.selectByPrimaryKey(projectInfoKey);

        return projectInfo;
    }

    /**
     * 入库管理项目审核不通过方法
     *
     * @param projectInfo
     * @return
     */
    @Override
    public ProjectInfo auditFail(ProjectInfo projectInfo) {
        if (projectInfo != null && projectInfo.getId() != null) {
            // 1审核通过状态
            projectInfo.setAuditStatus(2);
            projectInfoMapper.updateByPrimaryKeySelective(projectInfo);
        }
        ProjectInfo projectInfoKey = new ProjectInfo();
        projectInfoKey.setId(projectInfo.getId());
        projectInfo = projectInfoMapper.selectByPrimaryKey(projectInfoKey);

        return projectInfo;
    }

    /**
     * 入库管理,项目审批方法
     *
     * @param projectInfo
     * @return
     */
    @Override
    public ProjectInfo approval(ProjectInfo projectInfo) {
        // 修改项目审批状态 和 审批分类
        if (projectInfo != null && projectInfo.getId() != null) {
            // 已审批状态
            projectInfo.setApprovalStatus(1);
            projectInfoMapper.updateByPrimaryKeySelective(projectInfo);
        }

        ProjectInfo projectInfoKey = new ProjectInfo();
        projectInfoKey.setId(projectInfo.getId());
        projectInfo = projectInfoMapper.selectByPrimaryKey(projectInfoKey);
        return projectInfo;
    }

    /**
     * 入库管理,项目审批不通过方法
     *
     * @param projectInfo
     * @return
     */
    @Override
    public ProjectInfo approvalFail(ProjectInfo projectInfo) {
        // 修改项目审批状态 和 审批分类
        if (projectInfo != null && projectInfo.getId() != null) {
            // 已审批状态
            projectInfo.setApprovalStatus(2);
            projectInfoMapper.updateByPrimaryKeySelective(projectInfo);
        }

        ProjectInfo projectInfoKey = new ProjectInfo();
        projectInfoKey.setId(projectInfo.getId());
        projectInfo = projectInfoMapper.selectByPrimaryKey(projectInfoKey);
        return projectInfo;
    }

    @Override
    public ProjectInfo updateProjectType(ProjectInfo projectInfo) {
        // 修改项目审批状态 和 审批分类
        if (projectInfo != null && projectInfo.getId() != null) {
            projectInfoMapper.updateByPrimaryKeySelective(projectInfo);
        }
        ProjectInfo projectInfoKey = new ProjectInfo();
        projectInfoKey.setId(projectInfo.getId());
        projectInfo = projectInfoMapper.selectByPrimaryKey(projectInfoKey);
        return projectInfo;
    }

    /**
     * 条件查询 在库管理列表
     *
     * @param record
     * @return
     */
    @Override
    public PageResult selectInStoreProjectList(ProjectInfo record) {
        PageHelper.startPage(record.getPageNum(), record.getPageSize());
        List<ProjectInfo> list = projectInfoMapper.selectInStoreProjectList(record);
        PageInfo<ProjectInfo> pageInfo = new PageInfo<>(list);
        long count = pageInfo.getTotal();
        return PageResult.success(list, null, null, count);
    }

    @Override
    public PageResult getOutBoundList(ProjectInfo record) {
        PageHelper.startPage(record.getPageNum(), record.getPageSize());
        List<ProjectInfo> list = projectInfoMapper.getOutBoundList(record);
        List<ProjectInfo> list2 = new ArrayList<>();
        if (list.size() > 0) {
            for (ProjectInfo projectInfo : list) {
                int reason = 0;
                OutboundInfo outboundInfo = new OutboundInfo();
                outboundInfo.setProjectId(projectInfo.getId());
                List<OutboundInfo> list1 = outboundInfoMapper.selectByProjectId(outboundInfo);
                if (list1.size() > 0) {
                    reason = list1.get(0).getOutboundReason();
                }
                projectInfo.setReason(reason);
                list2.add(projectInfo);
            }
        }
        PageInfo<ProjectInfo> pageInfo = new PageInfo<>(list);
        long count = pageInfo.getTotal();
        return PageResult.success(list2, null, null, count);
    }

    @Override
    public ResultInfo updateOutStatus(ProjectInfo record) {
        OutboundInfo outboundInfo = new OutboundInfo();
        outboundInfo.setProjectId(record.getId());
        outboundInfoMapper.updateById(outboundInfo);

        ProjectInfo projectInfo = new ProjectInfo();
        projectInfo.setId(record.getId());
        projectInfo.setOutboundStatus(0);
        int i = projectInfoMapper.updateByPrimaryKeySelective(projectInfo);
        if (i > 0) {
            return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
        }
        return ResultUtil.createSuccess(Config.MESSAGE, 911, null);
    }


    @Override
    public int insert(ProjectInfo record) {
        return projectInfoMapper.insert(record);
    }

    @Override
    public int updateByPrimaryKey(ProjectInfo record) {
        return 0;
    }

    @Override
    public ResultInfo updateTypeById(ProjectInfo projectInfo) {
        projectInfoMapper.updateTypeById(projectInfo);
        return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
    }

    /**
     * 保存项目信息
     *
     * @param projectManager 项目信息对象
     * @return JsonData JsonData数据
     */
    @Override
    public JsonData saveProtect(ProjectManager projectManager) {
        projectManagerMapper.insert(projectManager);

        ProjectManager projectManager1 = new ProjectManager();
        projectManager1.setId(projectManager1.getId());
        projectManager1 = projectManagerMapper.selectByPrimaryKey(projectManager1);
        return JsonData.success("", 200);
    }

    /**
     * 根据条件分页查询申报项目
     *
     * @param searchMap 查询条件
     * @param pageNum   页数
     * @param pageSize  每页总数
     * @return PageResult PageResult对象
     */
    @Override
    public PageResult findList(SearchMap searchMap, Integer pageNum, Integer pageSize) {
        // 分页插件
        PageHelper.startPage(pageNum, pageSize);
        List<ProjectManager> projectManagers = projectManagerMapper.queryByAny(searchMap);
        PageInfo<?> pageInfo = new PageInfo<>(projectManagers);
        return PageResult.success(projectManagers, new ArrayList<>(), "", pageInfo.getTotal());
    }

    /**
     * 解析Json数据
     *
     * @param object 对象参数
     * @param type   对象类型
     * @return String 封装的返回参数
     */
    public String doValue(String object, String type) {
        String value;
        try {
            Map mapObject = (Map) JSON.parse(object);
            value = mapObject.get(type).toString();
        } catch (Exception ex) {
            value = "";
        }

        return value;
    }

    /**
     * 多条件分页查询
     *
     * @param projectManager
     * @return
     */
    @Override
    public PageResult selectProjectPagesList(ProjectManager projectManager) {
        // 分页插件
        PageHelper.startPage(projectManager.getPageNum(), projectManager.getPageSize());
        List<ProjectManager> list = projectManagerMapper.selectProjectPagesList(projectManager);
        PageInfo<ProjectManager> pageInfo = new PageInfo<>(list);
        Long count = pageInfo.getTotal();
        return PageResult.success(list, null, null, count);
    }

    /**
     * 入库管理项目审核方法
     *
     * @param projectManager
     * @return
     */
    @Override
    public ProjectManager auditList(ProjectManager projectManager) {
        if (projectManager != null && projectManager.getId() != null) {
            // 0未审核 1审核通过 2审核不通过状态
            // projectManager.setAuditStatus("1");
            projectManagerMapper.updateByPrimaryKeySelective(projectManager);
        }
        ProjectManager projectManagerKey = new ProjectManager();
        projectManagerKey.setId(projectManager.getId());
        projectManager = projectManagerMapper.selectByPrimaryKey(projectManagerKey);

        return projectManager;
    }

    /**
     * 入库管理项目审核不通过方法
     *
     * @param projectManager
     * @return
     */
    @Override
    public ProjectManager auditFailList(ProjectManager projectManager) {
        if (projectManager != null && projectManager.getId() != null) {
            // 0未审核 1审核通过 2审核不通过状态
            projectManager.setAuditStatus("2");
            projectManagerMapper.updateByPrimaryKeySelective(projectManager);
        }
        ProjectManager projectManagerKey = new ProjectManager();
        projectManagerKey.setId(projectManager.getId());
        projectManager = projectManagerMapper.selectByPrimaryKey(projectManagerKey);

        return projectManager;
    }

    /**
     * 项目信息修改
     *
     * @param projectManager
     * @return
     */
    @Override
    public ResultInfo updateProject(ProjectManager projectManager) {
        projectManager.setAuditStatus("0");
        projectManagerMapper.updateByPrimaryKeySelective(projectManager);
        return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
    }

    /**
     * 新增任务发布
     *
     * @param projectTaskManager 项目信息对象
     * @return JsonData JsonData数据
     */
    @Override
    public JsonData saveProtectList(ProjectTaskManager projectTaskManager) {
        projectTaskMapper.insertSelective(projectTaskManager);

        ProjectTaskManager projectTaskKey = new ProjectTaskManager();
        projectTaskKey.setId(projectTaskManager.getId());
        projectTaskManager = projectTaskMapper.selectByPrimaryKey(projectTaskKey);
        return JsonData.success("", 200);
    }

    /**
     * 新增发布通告
     *
     * @param projectTaskManager 项目信息对象
     * @return JsonData JsonData数据
     */
    @Override
    public JsonData SaveNotice(ProjectTaskManager projectTaskManager) {
        // 判断新增 or 修改编辑
        if (projectTaskManager.getId() != null && !"".equals(projectTaskManager.getId())) {
            // 修改
            projectTaskMapper.updateByPrimaryKeySelective(projectTaskManager);
            return JsonData.success(projectTaskManager, 906);
        } else {
            // 新增
            projectTaskManager.setId(UUIDBuild.getUUID());
            // 阅读状态,默认值为 0
            projectTaskManager.setStatus("0");
            // 获取当前系统时间和日期并格式化输出:
            projectTaskManager.setCreateTime(new Date());
            // 项目类型,发布通知为 0
            //projectTaskManager.setType("0");
            //项目id
            //projectTaskManager.setProjectId("projectId");
            //projectTaskManager.setTaskTime(new Date());
            projectTaskMapper.insertSelective(projectTaskManager);

            ProjectTaskManager projectTaskKey = new ProjectTaskManager();
            projectTaskKey.setId(projectTaskManager.getId());
            projectTaskManager = projectTaskMapper.selectByPrimaryKey(projectTaskKey);

            return JsonData.success(projectTaskManager, 906);
        }
    }

    /**
     * 多条件分页查询
     *
     * @param projectTaskManager
     * @return
     */
    @Override
    public PageResult selectProjectNoticeList(ProjectTaskManager projectTaskManager) {
        // 分页插件
        PageHelper.startPage(projectTaskManager.getPageNum(), projectTaskManager.getPageSize());
        List<ProjectTaskManager> list = projectTaskMapper.selectProjectNoticeList(projectTaskManager);
        PageInfo<ProjectTaskManager> pageInfo = new PageInfo<>(list);
        Long count = pageInfo.getTotal();
        return PageResult.success(list, null, null, count);
    }

    /**
     * 根据id查询
     *
     * @param projectTaskManager
     * @return
     */
    @Override
    public JsonData selectProjectByPrimaryKey(ProjectTaskManager projectTaskManager) {
        projectTaskManager = projectTaskMapper.selectByPrimaryKey(projectTaskManager);
        return JsonData.success(projectTaskManager, 906);
    }


    /**
     * 未审核列表查询
     *
     * @param projectManager
     * @return
     */
    @Override
    public PageResult getUnreviewedList(ProjectManager projectManager) {
        // 分页插件
        PageHelper.startPage(projectManager.getPageNum(), projectManager.getPageSize());
        List<ProjectManager> list = projectManagerMapper.getUnreviewedList(projectManager);
        PageInfo<ProjectManager> pageInfo = new PageInfo<>(list);
        Long count = pageInfo.getTotal();
        return PageResult.success(list, null, null, count);
    }


    /**
     * 根据主键删除提示记录
     *
     * @param object 主键id
     * @return ResultInfo 封装数据
     */
    @Override
    public ResultInfo deleteById(String object) {
        Map maps = (Map) JSON.parse(object);
        String[] list = JSONArray.parseArray(maps.get("id").toString()).toArray(new String[0]);
        for (int i = 0; i < list.length; i++) {
            String id = list[i];
            projectManagerMapper.deleteByPrimaryKey(id);
        }
        return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
    }

    /**
     * 项目管理 进度填报
     *
     * @param projectSchedule
     * @return JsonData JsonData数据
     */
    @Override
    public JsonData SaveProReport(ProjectSchedule projectSchedule) {

        // 若没有先谢过，则进行新增
        projectSchedule.setId(UUIDBuild.getUUID());
        // 获取当前系统时间
        projectSchedule.setProjectTime(new Date());

        projectSchedule.setStatus("0");
        //项目id
        // projectSchedule.setProjectId("projectId");
        int num = projectScheduleMapper.insertSelective(projectSchedule);

        if (num > 0) {
            ProjectManager projectManager = ProjectManager.builder()
                    .auditStatus("0")
                    .id(projectSchedule.getProjectId())
                    .projectFlow(projectSchedule.getProjectNode())
                    .operate("submit")
                    .build();
            int num1 = projectManagerMapper.updateByPrimaryKeySelective(projectManager);
            if (num > 0) {
                return JsonData.success("", 906);
            }
        }


        return JsonData.success(projectSchedule, 906);

    }

    /**
     * 项目管理 进度填报 更新
     *
     * @param projectSchedule
     * @return JsonData JsonData类型
     */
    @Override
    public JsonData updateProReport(ProjectSchedule projectSchedule) {
        // 获取当前系统时间
        projectSchedule.setProjectTime(new Date());
        projectSchedule.setStatus("0");
        //项目id
        // projectSchedule.setProjectId("projectId");
        int num = projectScheduleMapper.updateProjectSchedule(projectSchedule);

        if (num > 0) {
            ProjectManager projectManager = ProjectManager.builder()
                    .auditStatus("0")
                    .id(projectSchedule.getProjectId())
                    .quarterlyProgress(projectSchedule.getProjectSchedule())
                    .projectFlow(projectSchedule.getProjectNode())
                    .operate("submit")
                    .quarterPlan(projectSchedule.getProjectPlan())
                    .build();
            int num1 = projectManagerMapper.updateByPrimaryKeySelective(projectManager);
            if (num > 0) {
                return JsonData.success("", 906);
            }
        }

        return JsonData.success(projectSchedule, 906);

    }

    /**
     * 项目管理 进度填报
     *
     * @param record
     * @return
     */
    @Override
    public PageResult queryProjectList(ProjectSchedule record) {
        // 分页插件
        // PageHelper.startPage( pageNum, pageSize );
        List<ProjectSchedule> projectSchedules = projectScheduleMapper.queryProjectList(record);
        PageInfo<ProjectSchedule> pageInfo = new PageInfo<ProjectSchedule>(projectSchedules);
        Long count = pageInfo.getTotal();
        return PageResult.success(projectSchedules, null, "906", count);
    }


    /**
     * 修改阅读状态
     *
     * @param record
     * @return
     */
    @Override
    public ResultInfo updateReadStatus(ProjectTaskManager record) {
        ProjectTaskManager projectTaskManager = new ProjectTaskManager();
        projectTaskManager.setId(record.getId());
        projectTaskManager.setStatus("1");
        int i = projectTaskMapper.updateReadStatus(projectTaskManager);
        if (i > 0) {
            return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
        }
        return ResultUtil.createSuccess(Config.MESSAGE, 911, null);
    }

    /**
     * 储备主体  入库管理修改
     *
     * @param projectInfo
     * @return
     */
    public ResultInfo updateProject(ProjectInfo projectInfo) {
//        ProjectInfo projectInfo1 = projectInfoMapper.selectByPrimaryKey(projectInfo);
//        int num1 = 0;
        // 项目状态,默认值为 0
        projectInfo.setStatus(0);
        // 审核状态默认 0
        projectInfo.setAuditStatus(0);
        // 审批状态 默认 0
        projectInfo.setApprovalStatus(0);
        // 出库状态是 默认 0
        projectInfo.setOutboundStatus(0);
        // 获取当前系统时间和日期并格式化输出:
        Date date = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        // 格式转换.String
        String dateTime = df.format(date);
        projectInfo.setDeclareTime(dateTime);
        // 项目信息修改
        int num = projectInfoMapper.updateByPrimaryKeySelective(projectInfo);

        ProjectInfo projectInfo2 = projectInfoMapper.selectByPrimaryKey(projectInfo);

//        if (num1 > 0) {
        return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
//        }
//        else {
//            return ResultUtil.createSuccess(Config.MESSAGE, 911, null);
//        }

    }

    @Override
    public JsonData UpdateNotice(ProjectTaskManager projectTaskManager) {
        // 新增读取后附件上传
        projectTaskManager.setStatus(projectTaskManager.getStatus());
        projectTaskMapper.updateNotice(projectTaskManager);

        ProjectTaskManager projectTaskKey = new ProjectTaskManager();
        projectTaskKey.setId(projectTaskManager.getId());
        projectTaskManager = projectTaskMapper.selectByPrimaryKey(projectTaskKey);

        return JsonData.success(projectTaskManager, 906);

    }


    @Override
    public List<Object> FillWarning(String userId) {
        Calendar cal = Calendar.getInstance();
        String year = String.valueOf(cal.get(Calendar.YEAR));   //年
        int month = cal.get(Calendar.MONTH) + 1;  //月  默认是从0开始  即1月获取到的是0
        int totalDay = cal.getActualMaximum(Calendar.DATE);
        String season = null;
        if (month == 1 || month == 2 || month == 3) {
            season = "一";
        } else if (month == 4 || month == 5 || month == 6) {
            season = "二";
        } else if (month == 7 || month == 8 || month == 9) {
            season = "三";
        } else {
            season = "四";
        }
        int day = cal.get(Calendar.DAY_OF_MONTH);  //日，即一个月中的第几天
        List<ProjectManager> projectManagerList = projectManagerMapper.selectProjectInfoByUserId(userId);
        List<Object> projectList = new ArrayList<>();
        List<ProjectManager> info=null;
        for (ProjectManager p : projectManagerList) {
            List<ProjectSchedule> projectScheduleList = projectScheduleMapper.queryProjectInfo(p.getId());

            if (projectScheduleList.size() > 0) {
                for (ProjectSchedule s : projectScheduleList) {
                    if (s.getProjectYear() == year || s.getProjectYear().equals(year)) {
                        if (s.getProjectQuarter() == season || season.equals(s.getProjectQuarter())) {
                            continue;
                        } else {
                            if (day >= totalDay - 10) {
                                info = projectManagerMapper.selectById(p.getId());
                            }
                        }
                    }
                }
                projectList.add(info);
            }
        }
        return projectList;
    }
}
